import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/*
 * @Author: zhudaihao
 * @Date: 2022/3/4
 * @Describe:
 */
class Test1 extends StatelessWidget {
  const Test1({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    ///
    // return buildCupertinoPageScaffold();
    // return buildScaffold();

    return buildScaffold3();
  }

  CupertinoPageScaffold buildCupertinoPageScaffold() {
    return CupertinoPageScaffold(
        navigationBar: CupertinoNavigationBar(
          // backgroundColor: CupertinoColors.systemGrey.withOpacity(0.5),
          middle: const Text('Sample Code'), //模糊导航栏
        ),
        child: ListView.builder(
            // itemExtent: 100,
            itemCount: 100,
            //为列表创建100个不同颜色的RowItem
            itemBuilder: (context, index) {
              return GestureDetector(
                child: Column(
                  children: [
                    Container(
                      height: 100,
                      color: Colors.amber,
                      margin: const EdgeInsets.all(10),
                    ),
                  ],
                ),
                onTap: () {},
              );
            }));
  }

  Scaffold buildScaffold() {
    return Scaffold(
        appBar: AppBar(
          //设置半透明
          // backgroundColor: const Color.fromRGBO(
          //   196,
          //   196,
          //   199,
          //   0.8,
          // ),
          title: const Text("Sample Code"),
          centerTitle: true,
        ),
        body: ListView.builder(
            itemCount: 100,
            itemBuilder: (context, index) {
              return Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    width: 120,
                    height: 120,
                    color: Colors.yellow,
                    child: Image.network(
                      "https://img2.baidu.com/it/u=220990409,124547830&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
                      width: 50,
                      height: 50,
                    ),
                  ),
                  Container(
                    width: 120,
                    height: 120,
                    color: Colors.green,
                    child: Image.network(
                      "https://img2.baidu.com/it/u=957523443,3301463541&fm=253&fmt=auto&app=138&f=JPEG?w=700&h=497",
                      width: 50,
                      height: 50,
                    ),
                  ),
                  Container(
                    width: 120,
                    height: 120,
                    color: Colors.blue,
                    child: Image.network(
                      "https://img1.baidu.com/it/u=554809536,2732110137&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=560",
                      width: 50,
                      height: 50,
                    ),
                  ),
                ],
              );
            }));
  }

  Scaffold buildScaffold3() {
    return Scaffold(
        appBar: AppBar(
          title: const Text("Sample Code"),
          centerTitle: true,
        ),
        body: ListView.builder(itemBuilder: (context, index) {
          return Container(
            height: 150,
            color: Colors.amber,
            margin: const EdgeInsets.all(10),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                const SizedBox(
                  width: 10,
                ),
                FlatButton(
                  onPressed: () {},
                  child: const Text("按钮1"),
                  color: Colors.red,
                ),
                const SizedBox(
                  width: 10,
                ),
                FlatButton(
                  onPressed: () {},
                  child: const Text("按钮2"),
                  color: Colors.red,
                ),
                const SizedBox(
                  width: 10,
                ),
                FlatButton(
                  onPressed: () {},
                  child: const Text("按钮3"),
                  color: Colors.red,
                ),
              ],
            ),
          );
        }));
  }
}

class MyButton extends StatelessWidget {
  final Widget? child;
  final Color? color;
  final Function()? onPressed;
  final double? width;
  final double? height;
  final double? circular;

  const MyButton(
      {Key? key,
      this.onPressed,
      this.child,
      this.color,
      this.width,
      this.height,
      this.circular})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        alignment: Alignment.center,
        width: width ?? 86,
        height: height ?? 36,
        child: child,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(circular ?? 2),
          color: color,
        ),
      ),
      onTap: () {
        if (onPressed != null) {
          onPressed!();
        }
      },
    );
  }
}
